package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.damgesource.SkillDamageSource;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

public class PhoenixSkill extends BaseSkill {

    public PhoenixSkill(int level) {
        super(level);
    }

    public PhoenixSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public PhoenixSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setCooldown(10);
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return String.format("浴火技能，着火时候快速恢复(技能等级)生命。");
    }

    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    public boolean canUseAbility(MobEntity mobEntity) {
        return (mobEntity.getTarget() != null && getSkilltime() < mobEntity.world.getTime());
    }

    @Override
    public boolean passiveApply(MobEntity mobEntity) {
        if (canUseAbility(mobEntity)) {
            if (mobEntity.isOnFire()) {
                setSkilltime(mobEntity.world.getTime() + getCooldown());
                mobEntity.heal(getSkillLevel());
            }
        }
        return true;
    }

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if (source instanceof SkillDamageSource source1 && source1.getPassSkill()) return true;
        return !source.isFire();
    }
}
